#include "StateBase.h"

#include "StateResult.h"
#include "StateGraph.h"
#include "StateData.h"

//-------------------------------------------------------------------------
CStateBase::CStateBase(const char_t *szName) : m_szName(szName)
{
}

//-------------------------------------------------------------------------
CStateBase::CStateBase(const CStateDataPtr &pStateData)
{
	//\todo implement it prperly
}

//-------------------------------------------------------------------------
CStateGraph *CStateBase::GetParent()
{
	return m_pParent;
}

//-------------------------------------------------------------------------
CString &CStateBase::GetName()
{
	return m_szName;
}

//-------------------------------------------------------------------------
void CStateBase::SetParent(CStateGraph *pParent)
{
	m_pParent = pParent;
}

//-------------------------------------------------------------------------
void CStateBase::OnEnter(CStateResult *pResult)
{
	DoEnter(pResult);
}

//-------------------------------------------------------------------------
void CStateBase::OnUpdate(CStateResult *pResult)
{
	DoUpdate(pResult);
}

//-------------------------------------------------------------------------
void CStateBase::OnExit(CStateResult *pResult)
{
	DoExit(pResult);
}

//-------------------------------------------------------------------------
void CStateBase:: OnEvualuate(TTransitionList &vTriggeredTransitions)
{
	DoEvaluate(vTriggeredTransitions);
}

//-------------------------------------------------------------------------
void CStateBase::DoEnter(CStateResult *pResult)
{
	pResult->AddActions(m_vEntryActions);
}

//-------------------------------------------------------------------------
void CStateBase::DoExit(CStateResult *pResult)
{
	pResult->AddActions(m_vExitActions);
}

//-------------------------------------------------------------------------
void CStateBase::DoUpdate(CStateResult *pResult)
{
}


//-------------------------------------------------------------------------
void CStateBase::DoEvaluate(TTransitionList &vTriggeredTransitions)
{
	for(TTransitionList::iterator it = m_vTransitions.begin(); it != m_vTransitions.end(); ++it)
	{
		if((*it)->IsTrigger())
		{
			vTriggeredTransitions.push_back(*it);
		}
	}
}

//-------------------------------------------------------------------------
void CStateBase::AddEntryAction(const CActionPtr &pAction)
{
	m_vEntryActions.push_back(pAction);
}

//-------------------------------------------------------------------------
void CStateBase::AddExitAction(const CActionPtr &pAction)
{
	m_vExitActions.push_back(pAction);
}

//-------------------------------------------------------------------------
void CStateBase::AddAction(const CActionPtr &pAction)
{
	m_vActions.push_back(pAction);
}

//-------------------------------------------------------------------------
void CStateBase::AddTransition(const CTransitionPtr &pTransition)
{
	m_vTransitions.push_back(pTransition);
}

//-------------------------------------------------------------------------
void CStateBase::Clean()
{
	m_vTransitions.clear();
	m_vEntryActions.clear();
	m_vExitActions.clear();
	m_vActions.clear();
}



DEFINE_RTTI_CLASS( CStateBase, CFSMObject );